package com.scgl.process.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.process.domain.ScglReport;
import com.scgl.process.service.IScglReportService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 报工记录Controller
 *
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/report")
public class ScglReportController extends BaseController
{
    @Autowired
    private IScglReportService scglReportService;

    /**
     * 查询报工记录列表
     */
    @RequiresPermissions("process:report:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglReport scglReport)
    {
        startPage();
        List<ScglReport> list = scglReportService.selectScglReportList(scglReport);
        return getDataTable(list);
    }

    /**
     * 导出报工记录列表
     */
    @RequiresPermissions("process:report:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglReport scglReport)
    {
        List<ScglReport> list = scglReportService.selectScglReportList(scglReport);
        ExcelUtil<ScglReport> util = new ExcelUtil<ScglReport>(ScglReport.class);
        util.exportExcel(response, list, "报工记录数据");
    }

    /**
     * 获取报工记录详细信息
     */
    @RequiresPermissions("process:report:query")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(scglReportService.selectScglReportByProcessId(processId));
    }

    /**
     * 新增报工记录
     */
    @RequiresPermissions("process:report:add")
    @Log(title = "报工记录新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglReport scglReport)
    {
        return toAjax(scglReportService.insertScglReport(scglReport));
    }

    /**
     * 修改报工记录
     */
    @RequiresPermissions("process:report:edit")
    @Log(title = "报工记录修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglReport scglReport)
    {
        return toAjax(scglReportService.updateScglReport(scglReport));
    }

    /**
     * 删除报工记录
     */
    @RequiresPermissions("process:report:remove")
    @Log(title = "报工记录删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(scglReportService.deleteScglReportByProcessIds(processIds));
    }
}
